<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 * @category   Hamania
 * @package    Hamania_CashOnRelay
 * @copyright  Copyright (c) 2008-2009 Andrej Sinicyn, Mik3e
 * @copyright  Copyright (c) 2010 Hamania Medien GmbH & Co. KG (http://www.hamania-medien.de)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

class Hamania_CashOnRelay_Block_Form extends Mage_Payment_Block_Form
{

    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('cashonrelay/form.phtml');
    }

    public function getQuote(){
        return $this->getMethod()->getInfoInstance()->getQuote();
    }

    public function getShippingAddress(){
        return $this->getQuote()->getShippingAddress();
    }

    public function convertPrice($price, $format=false, $includeContainer = true)
    {
        return $this->getQuote()->getStore()->convertPrice($price, $format, $includeContainer);
    }                                              
		
		public function getAvailableRelays () 
		{
				$relay_ids = array() ;    
				foreach ($this->getQuote()->getAllVisibleItems() as $item) {   
						$product =  Mage::getModel('catalog/product')->load($item->getProductId());     
						$relay_ids = array_merge($relay_ids,$product->getRelayIds());       
				}     
				
				$relay_array = array() ;
					
				foreach (array_unique($relay_ids) as $relay_id) {    
					$relay =  Mage::getModel('relay/relay')->load($relay_id) ;    
					if (!$relay->getId()) continue ;
					$relay_array[$relay->getRelayId()] = $relay->getTitle(). ' - ' . $relay->getDesc() ;
				}
				
				return $relay_array ;
		}

}
